<template>
  <div class="dashboard-container">
      <el-upload
          ref="upload"
          accept=".doc,.docx"
          class="upload-demo"
          :file-list="fileList"
          :limit="1"
          :on-success="onSuccess"
          :on-remove="handleRemove"
          :on-exceed="handleExceed"
          :with-credentials="true"
          action="https://www.zbifc.com/sso/mh/app/xmfb/upFile"
          multiple>
          <el-button v-if="!isReview" class="el-upload__btn" size="small" type="primary">点击上传</el-button>
          <div v-if="!isReview" class="el-upload__tip" slot="tip">只能上传xls/xlsx文件，最多上传两个文件</div>
      </el-upload>
      <el-button type="success" @click="tes">啊的</el-button>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { test } from '@/api/user'

export default {
  name: 'Dashboard',
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  data() {
    return {
      input:{},
      fileList:[],
      files:[],
      isReview:false
    }
  },
  methods: {
    handleRemove(file, fileList) {
        console.log(file, fileList);
    },
    // 上传成功
    onSuccess(response, file, fileList) {
        console.log("onSuccess:response", response)
        console.log("onSuccess:file", file)
        console.log("onSuccess:fileList", fileList)
        this.files = [];
        //等待所有文件都上传完成，这里注意fileList是所有的文件（包含已上传的）
        if (fileList.every(it => it.status == 'success')) {
            fileList.map(item => {
                //只push新上传的 （带有response）
                item.response && this.files.push({ name: item.name, url: item.response.data[0] });
            })
        }
    },
    handleExceed(files, fileList) {
        this.$message.warning(
            `当前限制选择 2 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`
        );
    },
    async tes(){
      try{
        const res = await test();
      console.log("onSuccess:tes", res)
      }catch(err){

      }
     
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>
